package com.freecloud.whispered.system.controller;

import cn.hutool.core.util.StrUtil;
import com.freecloud.framework.request.Query;
import com.freecloud.framework.request.R;
import com.freecloud.framework.utils.PageUtils;
import com.freecloud.whispered.system.entity.SysLogEntity;
import com.freecloud.whispered.system.service.SysLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * 系统日志
 * 
 * @author maomao
 * @email 138383877@qq.com
 */
@RestController
@RequestMapping("/sys/log")
public class SysLogController {
	@Autowired
	private SysLogService sysLogService;
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("sys:log:list")
	public R list(@RequestParam Map<String, Object> params){

		String createDate = params.get("createDate") != null ? params.get("createDate").toString() : null;
		if(StrUtil.isEmpty(createDate))
		{
			params.remove("createDate");
		}

		Example<SysLogEntity> example = Query.getExample(params, SysLogEntity.class);
		Page<SysLogEntity> page = sysLogService.findAll(example,Query.getPageable(params,"id"));

		PageUtils pageUtil = new PageUtils(page.getContent(), Integer.parseInt(page.getTotalElements() + ""), page.getPageable().getPageSize(),  page.getPageable().getPageNumber() + 1);

		return R.ok().put("page", pageUtil);
	}
	
}
